package bigdata.api.weather.web;

import bigdata.api.weather.service.WeatherService;
import common.utils.gsonutil.GsonUtil;
import datacenterbizapiexternal.weather.domain.BaiduWeatherResponseParams;
import datacenterbizapiexternal.weather.service.BaiduWeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * 描述:
 *
 * @author 002465
 * @created 2017/6/7 20:48
 * @return ${return_type}
 * @since v1.0.0
 * ${tags}
 */
@Controller
@RequestMapping("/weather")
public class WeatherController {
    @Autowired
    private WeatherService weatherService;
    @RequestMapping(params = { "method=getGuanlingWeather" })
    @ResponseBody()
    public String getGuanlingWeather(String callback) {
        BaiduWeatherResponseParams enitty = weatherService.getGuanlingWeather(new Date());
        String jsonStr = "";
        if (enitty != null)
            jsonStr = GsonUtil.create().toJson(enitty);
        return getJsonp(callback,jsonStr);
    }

    @RequestMapping(params = { "method=getAnshunWeather" })
    @ResponseBody()
    public String getAnshunWeather(String callback) {
        BaiduWeatherResponseParams enitty = weatherService.getAnshunWeather(new Date());
        String jsonStr = "";
        if (enitty != null)
            jsonStr = GsonUtil.create().toJson(enitty);
        return getJsonp(callback, jsonStr);
    }

    private String getJsonp(String callback,String str){
        return new StringBuffer(callback).append("(").append(str).append(")").toString();
    }
}
